package org.jash.demo2205.utils

import android.content.Context
import androidx.room.Room
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import org.jash.demo2205.dao.ShopDatabase
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object HiltProvider {
    @Provides
    @Singleton
    fun getDatabase(@ApplicationContext context: Context) = Room.databaseBuilder(context, ShopDatabase::class.java, "shop.db")
        .fallbackToDestructiveMigration()
        .build()
    @Provides
    @Singleton
    fun getGoodsDao(database: ShopDatabase) = database.getGoodsDao()
}